import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { fileURLToPath, URL } from 'node:url'


import { createHtmlPlugin} from "vite-plugin-html";
// https://vitejs.dev/config/
export default ({ mode }) => {
  const { VITE_APP_TITLE } = loadEnv(mode,process.cwd())
  return defineConfig({
    base: './',
    server: {
      host: '0.0.0.0',
      port: 7979,
      open: true,
    },
    plugins: [
      vue(),
      // 按需引入插件配置
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver({importStyle: 'sass'})],
      }),
      createHtmlPlugin({
        inject: {
          data: {
            title: VITE_APP_TITLE
          }
        }
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          // 自动导入定制化样式文件进行样式覆盖
          additionalData: `
            @use "@/styles/element/index.scss" as *;
          `,
        }
      }
    }
  })
}

